#!/bin/bash

LLVM_VERSION=16.0.6
WORK_PATH=$(cd $(dirname $0) && pwd)
# BUILD_TYPE=Release
BUILD_TYPE=Debug

# sudo apt-get install -y gcc g++ git cmake ninja-build
# git clone https://github.com/llvm/llvm-project.git

PREFIX_DIR=${WORK_PATH}/bin

mkdir -p ${PREFIX_DIR}

cd llvm-project
git checkout -b llvmorg-${LLVM_VERSION} llvmorg-${LLVM_VERSION}

mkdir -p build
cd build

cmake -G Ninja -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \
	-DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" \
	-DCMAKE_INSTALL_PREFIX=${PREFIX_DIR} ../llvm
ninja -j16
# ninja check-all
# ninja install
